package com.dts.service.impl;

import com.dts.dto.UserDto;
import com.dts.entity.User;
import com.dts.mapper.UserMapper;
import com.dts.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(UserDto user) {
        user.setPassword(DigestUtils.md5DigestAsHex(user.getPassword().getBytes()));
        return userMapper.login(user);
    }

    @Override
    public boolean findByName(String name) {
        return userMapper.findByName(name);
    }

    @Override
    public void regiser(UserDto user) {
        user.setPassword(DigestUtils.md5DigestAsHex(user.getPassword().getBytes()));
        userMapper.regiser(user);
    }
}
